home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
TAWUG
/
TAWUG Disk No. 56 (SHK)
/
TAWUG56.shk
/
LOGO.NOTES
(
.txt
)
< prev
next >
Wrap
AppleWorks Document
|
1987-07-01
|
13KB
|
363 lines
O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
Page
PROGRAMMING IN APPLE LOGO
I. Introduction
@"Logo is a language for computers. Compared with natural human H
Flanguages like English or French, it has a very small number of words I
Gand grammatical rules. But Logo can be extended easily. In fact this J
His what programming in Logo is all about; using what exists to make new A
things, and then using the new things to make more new things."
G"The initial vocabulary words, which we refer to as Logo
primitives
Ideal with different kinds of computation including familiar ones such as @
>adding and subtracting numbers and less familiar ones such as )
manipulating words and lists of words."
H"A different kind of computation is chosen as the focus of this guide. F
DTechnically, the area is known as computer graphics. It has become J
Hfamiliar through computer art, special effects, and video games. As an K
Iintroductory route into programming, computer graphics has the advantage K
Ithat you can see how your programs work. Our experience is that this is F
Dan excellent way to develop and intuitive understanding of what all
programming is about."
----------------------------------------------------
II. Starting Logo
ITo start Logo with the computer off, first insert the Apple Logo program K
Idisk, then turn on the Apple power switch. The disk drive light will go J
Hon. After a few moments the light will go off, the drive will stop and '
your screen will display the message:
PRESS THE RETURN KEY TO BEGIN
IF YOU HAVE YOUR OWN FILE DISKETTE,"
INSERT IT NOW, THEN PRESS RETURN
HSimply press <Return> The disk drive will again be active and soon you
will see:
WELCOME TO LOGO
FThe question mark is a
prompt
, meaning that the computer is waiting E
Cfor your instructions. The flashing rectangle is the
cursor
and :
indicates where the next character you type will appear.
----------------------------------------------------
III. Printing with Logo
HType something into the keyboard, for example type "HELLO THERE". Then
press <Return>.
The computer will complain "I DON'T KNOW HOW TO HELLO".
Now type:
PRINT [HELLO THERE]
HBe sure to include the square brackets and press <Return>! If you make F
Da mistake you may use the left and right arrow keys to correct your K
Ityping BEFORE pressing <Return>. The <Return> key tells the computer to E
Caccept the line you just typed and act on it. The computer should H
Frespond by printing your message. Anything included in [ ] following J
Hthe command PRINT will be printed literally on the screen. If you omit F
the brackets you will be the error message "I DON'T KNOW HOW TO...."
Try some arithmetic:
PRINT 5 + 5
PRINT 321-123
PRINT 4/2
PRINT 4*2
IThe computer uses the * to indicate multiplication and the / to indicate
division.
Let's get rid of all this garbage. Now type:
CLEARTEXT
----------------------------------------------------
IV. Procedures
Type the command: GREET.
The computer responds, I DON'T KNOW HOW TO GREET.
IWe can store a set of commands in programs called
procedures
. In this &
way we can teach Logo
new commands.
?TO GREET
>PRINT [HELLO THERE]
>PRINT [BYE NOW]
HBe sure to separate TO and GREET with a space. Did you notice that the I
prompt changed from a ? to a > when you started defining the procedure?E
CThis is to remind you that you are not entering instructions to be F
Dcarried out right away. Use the word END to indicate that you have
finished. Logo will respond:
GREET DEFINED
Now run this little program by typing: GREET
This time Logo responds:
HELLO THERE
BYE NOW
We can have this program run several times successively. Try:
REPEAT 1000 [GREET]
IIf you wish to stop this procedure press CTRL-G. You do this by holding ;
down the <CONTROL> key and pressing <G> at the same time.
----------------------------------------------------
V. Turtle Graphics
GThe Logo "Turtle" was originally a robot attached to a computer with a H
Flong cable which could draw lines on the floor (covered with paper). C
Now the Turtle lives within the computer and draws on the screen.
To see the turtle give the command: SHOWTURTLE
GThe text screen will clear and the Turtle appears as a triangle in the @
center of the screen. The ? prompt now appears at the bottom.
Try to following commands, one at a time, and watch the results:
FORWARD 50
BACK 25
RIGHT 45
LEFT 45
IThese can be abbreviated to save typing: Forward = FD, Back = BK, Right F
= RT and Left = LT. You may also want to remember Clearscreen = CS.
Let's try
FD 50
RT 90
FD 50
RT 90
FD 50
RT 90
FD 50
RT 90
Play with these commands at your leisure.
ITry the commands HT, ST, PU and PD. What effects do they have? What do $
you suppose the letters stand for.
----------------------------------------------------
VI. The Logo Editor
JThere is another way to define a procedure. We can use the Logo Editor. I
GIn this environment typing mistakes can be corrected more easily. The K
ITurtle drawing screen will be replaced by the Editor screen. The way to 2
enter the Editor is with the EDIT or ED command.
EDIT "SQUARE
IThe quotation mark preceding the name of the procedure is essential! If E
Cyou omit this you will get the error message, "I DON'T KNOW HOW TO I
GSQUARE". Check the bottom of the screen. Does it say "Logo Editor"? I
Look at the top of the screen. It should contain the line "TO SQUARE".
Complete the procedure as follows:
TO SQUARE
FD 50 RT 90
FD 50 RT 90
FD 50 RT 90
FD 50 RT 90
HYou may combine commands on one line. Separate with a space for easier
viewing.
You may use these combinations of keys to edit the procedure:
CTRL-B to go back
CTRL-F to go forward
Back arrow to delete
FWhen finished press CTRL-C to define the procedure. Logo will return ;
you to the text screen with the message "SQUARE DEFINED".
Try the new command by typing: SQUARE
Type: RIGHT 45
Then: SQUARE
Try: REPEAT 6 [RT 45 SQUARE]
This could also be made into a procedure:
EDIT "SQUARESTAR
REPEAT 8 [SQUARE RT 45]
CTRL-C
Type CS then SQUARESTAR.
Experiment with the following:
TO FLAG
FD 30
SQUARE
TO CROSS
REPEAT 4 [FLAG RT 90]
TO FLAGBACK
BK 30
TO FLAGS
REPEAT 4 [FLAGBACK RT 90]
TO MANYFLAGS
FLAGS
RT 45
FLAGS
Experiment with the effects of:
CTRL-T (textscreen)
CTRL-S (splitscreen)
CTRL-L (fullscreen)
----------------------------------------------------
VII. Saving and Loading
If your own disk is in the drive, you can save your procedures.
Type: SAVE "SQUARES
All of the procedures are now saved in a file named "SQUARES".
GAt some later time you can then retrieve these procedures and use them
again without retyping.
Type: LOAD "SQUARES
To see what is on your disk type: CATALOG
----------------------------------------------------
VIII. Variables
ESuppose that we wanted to draw boxes of different sizes. Each would A
?have a different length for its sides. We could make separate K
Iprocedures for each size box, or we could designate the size of the side I
Gas a variable. Then all we need to do is tell the procedure what size
to use for the variable.
EDIT "BOXR :SIDE
IThe colon (:) tells logo that "side" is a variable. It will then expect ,
a number to be given whenever BOXR is run.
Complete the procedure:
TO BOXR :SIDE
FD :SIDE
RT 90
FD :SIDE
RT 90
FD :SIDE
RT 90
FD :SIDE
RT 90
CTRL-C
Now run:
BOXR 10
BOXR 20
BOXR 30
BOXR 40
Try some of these:
TO SQUARES
BOXR 10
BOXR 20
BOXR 30
BOXR 40
TO DIAMONDS
RT 45
REPEAT 4 [SQUARES RT 90]
TO FLAGR :SIZE
FD :SIZE
BOXR :SIZE
BK :SIZE
TO 6FLAG :SIZE
REPEAT 6 [FLAG :SIZE RT 60]
TO SPINFLAG :SIZE
6FLAG :SIZE
6FLAG :SIZE - 20
TO TRIANGLER :SIDE
REPEAT 3 [FD :SIDE RT 120]
TO TRIANGLES
TRIANGLER 10
TRIANGLER 20
TRIANGLER 30
TRIANGLER 40
TO TRISTAR
REPEAT 10 [TRIANGLES RT 36]
TO TREE :SIDE
RT 30 TRIANGLER :SIDE
RT 60 FD :SIDE / 2
LT 90 BK :SIDE / 2
TO TREES
TREE 30
TREE 40
TREE 50
----------------------------------------------------
VIII. Circles, Polygons and Arcs
Try these:
REPEAT 360 [FD 1 RT 1]
CIRCLER (right) and CIRCLEL (left) can be used as well. Try them:
CIRCLER 20
CIRCLER 10
CIRCLEL 20
CIRCLEL 10
Let's make a face, which will include several new component procedures.
TO FACE :SIZE
HEAD :SIZE
EYES :SIZE / 5
MOUTH :SIZE / 5
NOSE :SIZE / 5
TO HEAD :SIZE
PU FD :SIZE
RT 90
PD CIRCLER :SIZE
PU LT 90
BK :SIZE PD
TO EYES :SIZE
LEYE :SIZE
REYE :SIZE
TO LEYE :S
PU LT 90 FD :S PD
CIRCLER :S / 2
PU BK :S RT 90 PD
TO REYE :S
PU RT 90 FD :S PD
CIRCLEL :S / 2
PU BK :S LT 90 PD
TO MOUTH :SIZE
PU BK 2 * :SIZE
RT 90 FD :SIZE / 2
PD BK :SIZE
PU FD :SIZE
LT 90 FD 2 * :SIZE
TO NOSE :S
BK :S
Experiment with variables in polygons:
TO POLY :STEP :ANGLE
FD :STEP
RT :ANGLE
POLY :STEP :ANGLE
Try: POLY 30 90 or POLY 30 120 or POLY 30 60 or POLY 30 72
We also have arcs at our disposal. We use ARCR and ARCL.
Experiment with these:
TO PETAL :SIZE
ARCR :SIZE 90 RT 90
ARCR :SIZE 90 RT 90
Try: PETAL 40 or PETAL 30*
REPEAT 8 [PETAL 40 PETAL 30 RT 45]0
REPEAT 4 [PETAL 30 RT 45 PETAL 40 RT 45]
How about building a swan?
TO SWAN :SIZE
BODY :SIZE
NECK :SIZE / 2
HEAD :SIZE / 4
TO BODY :SIZE
RT 45
PETAL :SIZE
LT 45
TO NECK :SIZE
LT 45
ARCR :SIZE 90
ARCL :SIZE 90
RT 45
TO HEAD :SIZE
LT 135
PETAL :SIZE
RT 135
----------------------------------------------------
IX. Recursion
?Recursion is Logo's ability to use a procedure within the same D
Bprocedure. It is the most significant and powerful aspect of the K
Ilanguage. In the following examples, notice how the procedure SPI calls
itself in the last line.
TO SPI :STEP :ANGLE :INC
FD :STEP
RT :ANGLE
SPI :STEP + :INC :ANGLE :INC
FTry these and any other combinations you desire. Remember, this is a 0
loop that will never stop. Use CTRL-G to end.
SPI 5 90 2
SPI 5 120 2
SPI 5 60 2
SPI 5 144 2
SPI 5 125 2
SPI 5 160 2
SPI 5 75 1
SPI 5 75 2
----------------------------------------------------
X. Color and Graphics
GBoth the color of the background and the color of the Turtle's pen can 6
be changed. The colors are number-coded as follows:
0 is Black
1 is White
2 is Green
3 is Violet
4 is Orange
5 is Blue
Try changing the background with the SETBG command.
TO CB
SETBG 1 WAIT 20
SETBG 2 WAIT 20
SETBG 3 WAIT 20
SETBG 4 WAIT 20
SETBG 5 WAIT 20
SETBG 0 WAIT 20
FThe WAIT command simply tells the computer to pause for the specified
length of time.
Now try changing the pen color with SETPC.
TO COLORSQUARES
SETBG 0
SETPC 2 SQUARE
RT 90 SETPC 3 SQUARE
RT 90 SETPC 4 SQUARE
RT 90 SETPC 5 SQUARE
----------------------------------------------------
This material is excerpted from "Apple Logo, Introduction to I
GProgramming
through Turtle Graphics", copyright 1982 by Logo Computer
Systems, Inc.